﻿Imports EHaskins.Frc.Dashboard
Imports EHaskins.Frc.Infrastructure
Imports System.ComponentModel
Imports System.Collections.ObjectModel

Public Interface IStandardDataViewModel
    Property View() As StandardDataView
End Interface
Public Class StandardDataViewModel
    Implements INotifyPropertyChanged
    Implements IStandardDataViewModel

    Private Sub RaisePropertyChanged(ByVal prop As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(prop))
    End Sub
    Dim _dashController As IDashboardController
    Dim _currentProcessor As DefaultUserDataProcessor

    ''' <summary>
    ''' Initializes a new instance of the StandardDataViewModel class.
    ''' </summary>
    ''' <param name="dashController"></param>
    Public Sub New(ByVal dashController As IDashboardController)
        _dashController = dashController
        UpdateProcessor()
        AddHandler _dashController.PropertyChanged, AddressOf Me.DashPropChanged
        View = New StandardDataView()
        View.DataContext = Me
    End Sub

    Private Sub UpdateProcessor()
        'If _currentProcessor IsNot Nothing Then
        'RemoveHandler _currentProcessor.PropertyChanged, AddressOf Me.CurrentProcPropChanged
        'End If

        If _dashController.CurrentProcessor IsNot Nothing Then
            Try
                CurrentProcessor = _dashController.CurrentProcessor
                'AddHandler _currentProcessor.PropertyChanged, AddressOf Me.CurrentProcPropChanged
            Catch ex As Exception
                CurrentProcessor = Nothing
            End Try
            RaisePropertyChanged("PrintedStrings")
            RaisePropertyChanged("ErrorStrings")
            RaisePropertyChanged("TeamNumber")
        End If
    End Sub

    Private Sub DashPropChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
        Select Case e.PropertyName
            Case "CurrentProcessor"
                UpdateProcessor()
        End Select
    End Sub

    Public Property CurrentProcessor() As DefaultUserDataProcessor
        Get
            Return _currentProcessor
        End Get
        Set(ByVal value As DefaultUserDataProcessor)
            If _currentProcessor Is value Then
                Return
            End If
            _currentProcessor = value
            RaisePropertyChanged("CurrentProcessor")
        End Set
    End Property
    'Private Sub CurrentProcPropChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
    '    Select Case e.PropertyName
    '        Case "PrintedStrings"
    '            RaisePropertyChanged("PrintedStrings")
    '        Case "ErrorStrings"
    '            RaisePropertyChanged("ErrorStrings")
    '        Case "TeamNumber"
    '            RaisePropertyChanged("TeamNumber")
    '    End Select
    'End Sub


    Private _header As String = "Standard data"
    Public Property Header() As String
        Get
            Return _header
        End Get
        Set(ByVal Value As String)
            _header = Value
        End Set
    End Property
    Private _view As StandardDataView
    Public Property View() As StandardDataView Implements IStandardDataViewModel.View
        Get
            Return _view
        End Get
        Set(ByVal Value As StandardDataView)
            _view = Value
        End Set
    End Property

    'Public Property PrintedStrings() As ObservableCollection(Of String)
    '    Get
    '        Return _currentProcessor.PrintedStrings
    '    End Get
    '    Set(ByVal value As ObservableCollection(Of String))
    '        _currentProcessor.PrintedStrings = value
    '    End Set
    'End Property

    'Public Property ErrorStrings() As ObservableCollection(Of String)
    '    Get
    '        Return _currentProcessor.ErrorStrings
    '    End Get
    '    Set(ByVal value As ObservableCollection(Of String))
    '        _currentProcessor.ErrorStrings = value
    '    End Set
    'End Property

    'Public Property TeamNumber() As Integer
    '    Get
    '        Return _currentProcessor.TeamNumber
    '    End Get
    '    Set(ByVal value As Integer)
    '        _currentProcessor.TeamNumber = value
    '    End Set
    'End Property

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
End Class
